<?php
	
	class ServerCRUDCommand implements ICommand
	{
		public function execute ($event)
		{
			$modelname = $event->data["modelname"];
			$operation = $event->data["operation"];
			$item = $event->data["item"];
						
			if (!is_null($item))
			{
				$item = (object) $item;
			}
			
			if (strpos($modelname,'/'))
			{
				$module = substr($modelname,0,strpos($modelname,'/'));
				$modelname = substr($modelname,strpos($modelname,'/') + 1);
				
				$model = EbModel::getModel($module,$modelname);
			}
			else
			{
				$model = EbModel::getModel("Core",$modelname);
			}
					
			if ($operation == "read")
			{
				return $model->select();
			}
			elseif ($operation == "create")
			{
				return $model->insert($item);
			}
			elseif ($operation == "delete")
			{
				return $model->delete($item);
			}
			elseif ($operation == "update")
			{
				return $model->update($item);
			}
			else
			{
				return $model->$operation($event->data['param']);
			}
		}
		
function array2object(array $array) {
	$object = new stdClass();
	foreach($array as $key => $value) {
		/*if(is_array($value)) {
			$object->$key = array2object($value);
		} else {*/
			$object->$key = $value;
		//}
	}
	return $object;
}
		
	}